package com.reggie.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class R<T> {
    private Integer code;
    private String message;
    private String msg;
    private T data;
    private Map map = new HashMap();//动态数据

    /**
     * @param Object
     * @return com.reggie.common.R<T>
     * @description: 处理正确的响应
     * @author 86187
     * @date: 2022/11/15 11:24
     */

    public static <T> R<T> success(T Object) {
        R<T> r = new R<>();
        r.code = 1;
        r.data = Object;
        return r;
    }

    /**
     * @param msg
     * @return com.reggie.common.R<T>
     * @description: 处理错误的响应
     * @author 86187
     * @date: 2022/11/15 11:27
     */

    public static <T> R<T> error(String msg) {
        R r = new R();
        r.msg = msg;
        r.code = 0;
        return r;
    }

    public R<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }

}
